package com.headwind.logistics.carrier.controller;

import com.headwind.logistics.carrier.dto.CarRegisterDto;
import com.headwind.logistics.carrier.service.inter.CarRegisterServiceInter;
import com.headwind.logistics.common.pojo.CarRegister;
import com.headwind.logistics.common.util.LayuiUtil;
import com.headwind.logistics.common.util.RestResult;
import com.headwind.logistics.common.util.ResultGenerator;
import com.headwind.logistics.log.annotate.Log;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author QT
 * @Date 2020/7/24 15:05
 * @Version 1.0
 * @DESCRIPTION 车辆登记控制器层
 */
@Controller
public class CarRegisterController {
    //车辆登记业务逻辑接口层
    @Resource
    private CarRegisterServiceInter carRegisterServiceInter;

    //api统一响应格式
    @Resource
    private ResultGenerator resultGenerator;
    /**
     * 查询车辆登记表数据和模糊查询并分页
     * @param tansportName 运输人名字
     * @param page 页码
     * @param limit 行数
     * @return
     */
    @GetMapping("/admin/carrier/queryAllCarRegister")
    @ResponseBody
    @Log("查询车辆登记表数据和模糊查询并分页")
    public LayuiUtil queryAllCarRegister(String tansportName,Integer page,Integer limit){
      List<CarRegisterDto> list= carRegisterServiceInter.queryAllCarRegister(tansportName,page,limit);
      return  LayuiUtil.data(carRegisterServiceInter.queryAllCarRegister(tansportName,null,null).size(),list);
    }

    /**
     * 修改车辆登记状态
     * @param carRegister 车辆登记实体对象
     * @return
     */
    @PostMapping("admin/carrier/updateCarRegisterStatus")
    @ResponseBody
    @Log("修改车辆登记状态")
    public RestResult updateCarRegisterStatus(CarRegister carRegister){
        int count=carRegisterServiceInter.updateCarRegisterStatus(carRegister);
        if(count>0){
            return resultGenerator.getSuccessResult("更改成功",count);
        }
        return resultGenerator.getFailResult("更改失败",count);
    }
}
